package gui.util;

import com.jgoodies.forms.layout.ColumnSpec;
import com.jgoodies.forms.layout.FormLayout;
import com.jgoodies.forms.layout.FormSpec;
import com.jgoodies.forms.layout.RowSpec;
import com.jgoodies.forms.layout.Sizes;

public class GUIUtils {
	public static FormLayout getLayout( int rows, int columns ) {
		columns *= 2;

		ColumnSpec[] col = new ColumnSpec[columns];

		int i = 0;
		while (i < (columns-1)) {
			col[i] = new ColumnSpec( Sizes.pixel(5) );
			i++;

			col[i] = i == columns-2 ? new ColumnSpec(ColumnSpec.FILL, Sizes.pixel(20), FormSpec.DEFAULT_GROW ) : new ColumnSpec( Sizes.pixel(20) );
			i++;
		}
		col[columns - 1] = new ColumnSpec( Sizes.pixel(5) );

		rows *= 2;

		RowSpec[] row = new RowSpec[rows];

		i = 0;
		while (i < (rows-1)) {
			row[i] = new RowSpec( Sizes.pixel(5) );
			i++;
			row[i] = i == rows-2 ? new RowSpec(RowSpec.FILL, Sizes.pixel(20), FormSpec.DEFAULT_GROW ) : new RowSpec( Sizes.pixel(20) );
			i++;
		}
		row[rows - 1] =  new RowSpec( Sizes.pixel(5) );


		return new FormLayout(col, row);
	}
}
